package com.aerozhonghuan.logisticsmall.modules.mine.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.aerozhonghuan.logisticsmall.R;
import com.aerozhonghuan.logisticsmall.modules.home.GoodsDetailsActivity;
import com.aerozhonghuan.logisticsmall.modules.mine.beans.MenuItem;
import com.aerozhonghuan.logisticsmall.modules.order.beans.OrdersListBean;

import java.util.List;

/**
 * 描述 个人中心通用item Adapter
 * @author zhangyonghui
 * 创建日期 2019-05-23
 */
public class OrderInfoPlistAdapter extends BaseAdapter {
    private Context context;
    private List<OrdersListBean.CommodityListBean> items;
    private LayoutInflater mLayoutInflater;

    public OrderInfoPlistAdapter(List<OrdersListBean.CommodityListBean> datasource, Context context) {
        this.mLayoutInflater = LayoutInflater.from(context);
        this.items = datasource;
        this.context = context;
    }

    @Override
    public int getCount() {
        return items == null ? 0 : items.size();
    }

    @Override
    public OrdersListBean.CommodityListBean getItem(int position) {
        return items == null ? null : items.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = (ViewGroup) mLayoutInflater.inflate(R.layout.item_orderinfo_plist, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        OrdersListBean.CommodityListBean item = getItem(position);
        viewHolder.tvBasename.setText(item.getBaseName());
        viewHolder.tvBrand.setText(String.format("%s  %s", item.getBrand(), item.getSpec()));
        viewHolder.tvNumber.setText(String.format("x%s", item.getNumber()));
        viewHolder.tvPrice.setText(String.format("¥ %s", (float)item.getPrice()/100));
        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                Toast.makeText(context, "跳转商品详情", Toast.LENGTH_SHORT).show();
            }
        });
        return convertView;
    }

    public class ViewHolder {
        public ImageView imgCommodity;
        public TextView tvBasename;
        public TextView tvPrice;
        public TextView tvNumber;
        public TextView tvBrand;

        public ViewHolder(View convertView) {
            imgCommodity = (ImageView) convertView.findViewById(R.id.img_commodity);
            tvBasename = (TextView) convertView.findViewById(R.id.tv_basename);
            tvPrice = (TextView) convertView.findViewById(R.id.tv_price);
            tvNumber = (TextView) convertView.findViewById(R.id.tv_number);
            tvBrand = (TextView) convertView.findViewById(R.id.tv_brand);
        }
    }
}
